/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.powerhua.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import junit.framework.TestCase;

/**
 *
 * @author Administrator
 */
public class JavascriptUtils extends TestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }
    
    private static String BASE_PATH = "D:/Brian/dev/project/xsys/web/js/components/form/themes";

    public void testGenJsStr() throws Exception {
        String str = getPageContent("table");
        System.out.println(str);
    }
    
    public void testGenTextJsStr() throws Exception {
        String str = getPageContent("inputText");
        System.out.println(str);
    }

    private String getPageContent(String fileName) {
        StringBuffer result = new StringBuffer("");

        String pathTmp = BASE_PATH + "/" + fileName + ".html";
        String content = getTextFileStr(pathTmp, "UTF-8");
        int start = content.indexOf("<body>");
        int end = content.indexOf("</body>");
        content = content.substring(start + 6, end);
        result.append(content);

        return result.toString();
    }

    private String getTextFileStr(String filePath, String coding) {
        StringBuffer sb = new StringBuffer();
        BufferedReader reader;
        try {
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(filePath), coding));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                sb.append(tempStr.trim());
            //sb.append(System.getProperty("line.separator"));
            }
            reader.close();
        } catch (Exception e) {
            // TODO 
            e.printStackTrace();
        }
        return sb.toString();
    }
}
